﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：ConsumablesInfo
// 文件功能描述：零星物品实体类
//
// 
// 创建标识：2012-01-14 zhou
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    public class InstockSporadicInfo
    {
        public InstockSporadicInfo(bool isgetcount)
        {
            Dais = new DataAccessInstockSundries();
            if (isgetcount)
            {
                sundriescount = Dais.GetRowCount("");
            }
        }

        public InstockSporadicInfo()
        { }

        /// <summary>
        /// 自增ID主键
        /// </summary>
        public int ID
        {
            get;
            set;
        }
        /// <summary>
        /// 入库日期
        /// </summary>
        public DateTime InstockDt
        {
            get;
            set;
        }
        /// <summary>
        /// 零星物品
        /// </summary>
        public int Goods_ID
        {
            get;
            set;
        }
        /// <summary>
        /// 数量
        /// </summary>
        public decimal Count
        {
            get;
            set;
        }
        /// <summary>
        /// 使用人
        /// </summary>
        public string UserMan
        {
            get;
            set;
        }
        /// <summary>
        /// 备注
        /// </summary>
        public string Remark
        {
            get;
            set;
        }
        /// <summary>
        /// 记录时间
        /// </summary>
        public DateTime RecordDateTime
        {
            get;
            set;
        }
        /// <summary>
        /// 操作人
        /// </summary>
        public string OperatorID
        {
            get;
            set;
        }
        /// <summary>
        /// 批号
        /// </summary>
        public string OrderNo
        {
            get;
            set;
        }

        private DataAccessInstockSundries Dais;
        private int sundriescount;
        public int _SundriesCount
        {
            get { return sundriescount; }
        }

        /// <summary>
        /// 保存零星物品入库
        /// </summary>
        /// <param name="igpara"></param>
        /// <returns></returns>
        public int SaveSundries(InstockSporadicInfo insp)
        {
            object[] sspara = new object[] { insp.ID,insp.InstockDt,insp.Goods_ID, insp.Count, insp.UserMan,
                                             insp.Remark,insp.RecordDateTime,insp.OperatorID,insp.OrderNo };
            return Dais.SaveSundries(sspara);            
        }

        /// <summary>
        /// 获取一条零星物品入库信息
        /// </summary>
        /// <param name="ID">主键</param>
        /// <returns>零星物品入库信息</returns>
        public InstockSporadicInfo GetInstockGroup(int ID)
        {
            DataRow item = Dais.GetInstockGroup(ID);
            InstockSporadicInfo inspinfo = new InstockSporadicInfo()
                {
                    ID = Convert.ToInt32(item[0]),
                    InstockDt = Convert.ToDateTime(item[1]),
                    Goods_ID = Convert.ToInt32(item[2]),
                    Count = Convert.ToDecimal(item[3]),
                    UserMan = item[4].ToString(),
                    Remark = item[5].ToString(),
                    RecordDateTime = Convert.ToDateTime(item[6]),
                    OperatorID = item[7].ToString(),
                    OrderNo = item[8].ToString()
                };
            return inspinfo;
        }

        /// <summary>
        /// 获取零星物品入库信息
        /// </summary>
        /// <param name="pagesize">页大小</param>
        /// <param name="startindex">起始页</param>
        /// <param name="dict">查询条件</param>
        /// <returns>零星物品入库信息</returns>
        public IList<InstockSporadicInfo> GetInstockGroup(int pagesize, int startindex,string condition)
        {
            DataSet ds = Dais.GetInstockGroup(pagesize, startindex, condition);
            IList<InstockSporadicInfo> insplist = new List<InstockSporadicInfo>();
            InstockSporadicInfo inspinfo;
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                inspinfo = new InstockSporadicInfo()
                {
                    ID = Convert.ToInt32(item[0]),
                    InstockDt = Convert.ToDateTime(item[1]),
                    Goods_ID = Convert.ToInt32(item[2]),
                    Count = Convert.ToDecimal(item[3]),
                    UserMan = item[4].ToString(),
                    Remark = item[5].ToString(),
                    RecordDateTime = Convert.ToDateTime(item[6]),
                    OperatorID = item[7].ToString(),
                    OrderNo = item[8].ToString()
                };
                insplist.Add(inspinfo);
            }
            return insplist;
        }

        /// <summary>
        /// 获取零星物品入库信息(不分页）
        /// </summary>
        /// <param name="dict">查询条件</param>
        /// <returns>零星物品入库信息</returns>
        public IList<InstockSporadicInfo> GetInstockGroup(string condition)
        {
            DataSet ds = Dais.GetInstockGroup(condition);
            IList<InstockSporadicInfo> insplist = new List<InstockSporadicInfo>();
            InstockSporadicInfo inspinfo;
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                inspinfo = new InstockSporadicInfo()
                {
                    ID = Convert.ToInt32(item[0]),
                    InstockDt = Convert.ToDateTime(item[1]),
                    Goods_ID = Convert.ToInt32(item[2]),
                    Count = Convert.ToDecimal(item[3]),
                    UserMan = item[4].ToString(),
                    Remark = item[5].ToString(),
                    RecordDateTime = Convert.ToDateTime(item[6]),
                    OperatorID = item[7].ToString(),
                    OrderNo = item[8].ToString()
                };
                insplist.Add(inspinfo);
            }
            return insplist;
        }

        /// <summary>
        /// 删除零星物品入库
        /// </summary>
        /// <param name="ID">主键</param>
        /// <returns></returns>
        public int DeleteInstockGroup(int id)
        {
            return Dais.DeleteInstockGroup(id);
        }

        /// <summary>
        /// 获取零星物品的数据
        /// </summary>
        /// <returns></returns>
        public int GetRowCount(string condition )
        {
            return Dais.GetRowCount(condition);
        }
          /// <summary>
        /// 获取批号
        /// </summary>
        /// <returns></returns>
        public string GetInstockSporadicOrderNo()
        {
            return Dais.GetInstockSporadicOrderNo();
        }
    }
}
